package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.QualityInspectionStandardsDao;
import com.tac.pojo.mes.QualityInspectionStandards;
import com.tac.service.mes.QualityInspectionStandardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QualityInspectionStandardsServiceImpl implements QualityInspectionStandardsService {

    @Autowired
    private QualityInspectionStandardsDao qualityInspectionStandardsDao;

    @Override
    public Result<PageInfo<QualityInspectionStandards>> getList(Integer pageNum, Integer pageSize,
                                                                String materialName, String inspectionItem,
                                                                String inspectionType) {
        PageHelper.startPage(pageNum, pageSize);
        List<QualityInspectionStandards> list = qualityInspectionStandardsDao.getList(materialName, inspectionItem, inspectionType);
        PageInfo<QualityInspectionStandards> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @Override
    public Result insert(QualityInspectionStandards qualityInspectionStandards) {
        Integer count = qualityInspectionStandardsDao.save(qualityInspectionStandards);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("添加失败");
        }
    }

    @Override
    public Result update(QualityInspectionStandards qualityInspectionStandards) {
        Integer count = qualityInspectionStandardsDao.update(qualityInspectionStandards);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("更新失败");
        }
    }

    @Override
    public Result delete(List<Integer> ids) {
        Integer count = qualityInspectionStandardsDao.remove(ids);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("删除失败");
        }
    }
}
